﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class FloatingText : MonoBehaviour
{
    public Vector3 offset = Vector3.up * 0.1f;
    public float frequency = 1f;
    private Text _text;
    private Vector3 initPos;
    public GameObject background;

    // Start is called before the first frame update
    void Awake()
    {
        _text = GetComponentInChildren<Text>();
        initPos = _text.rectTransform.localPosition;
    }

    // Update is called once per frame
    void Update()
    {
        _text.rectTransform.localPosition = initPos + offset * Mathf.Sin(Time.time * frequency);

    }

    public void SetText(string newText)
    {
        _text.text = newText;
        background.SetActive(_text.text != "");
    }
}
